/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;
import java.io.*;
import java.net.URL;
import javax.sound.sampled.*;
/**
 *
 * @author Anjori
 */
public enum SoundEffect {
    INTRO("Resources/pacintro.wav");  //introduction
    
    
    public static enum Volume{
        MUTE, LOW, MEDIUM, HIGH;    //to specify volume
    }
    
    public static Volume volume = Volume.MEDIUM;
    
    private Clip clip; 
    
    //Constructor to construct each element with own sound file
    SoundEffect(String soundFileName){
        try {
           
          // Use URL (instead of File) to read from disk and JAR.
         URL url = this.getClass().getClassLoader().getResource(soundFileName);
         // Set up an audio input stream piped from the sound file.
         AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
         // Get a clip resource.
         clip = AudioSystem.getClip();
         // Open audio clip and load samples from the audio input stream.
         clip.open(audioInputStream);
        }
        catch (UnsupportedAudioFileException e) {
            e.printStackTrace();        
        }
        catch (IOException e) {
            e.printStackTrace();
        } 
        catch (LineUnavailableException e) {
            e.printStackTrace();
        }
    }
    
    public void play() {
        if(volume != Volume.MUTE) {
            if(clip.isRunning())
                clip.stop();    //Stop if running
            clip.setFramePosition(0);   //rewind
            clip.start();   //start playing
        }
    }

}
